<template>
    <div id="root">
        <div class="container">
            <div class="title">社区团购后台管理系统</div>
            <el-row class="inputs">
                <el-col :span="6">用户名:</el-col>
                <el-col :span="16">
                    <el-input v-model="user.username" placeholder="请输入用户名" @keyup.enter.native="login"></el-input>
                </el-col>
                <el-col :span="2">&nbsp;</el-col>
            </el-row>
            <el-row  class="inputs">
                <el-col :span="6">密码:</el-col>
                <el-col :span="16">
                    <el-input v-model="user.password" type="password" placeholder="请输入密码" @keyup.enter.native="login"></el-input>
                </el-col>
                <el-col :span="2">&nbsp;</el-col>
            </el-row>

            <div class="btn" @click="login">登录</div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            user: {
                username: "",
                password: ""
            }
        }
    },
    methods: {
        login() {
            this.$http.post("/v1/user/login", this.user)
                .then(res => {
                    if (res.code == 200) {
                        let user = res.data;
                        //保存登录信息
                        localStorage.setItem("loginuser", user.username);
                        //跳转
                        this.$router.push("/main");
                    } else {
                        this.$message.error(res.msg);
                    }
                })
        }
    }
}
</script>

<style>
#root {
    width: 100%;
    height: 100%;
    background: url(../assets/bg.jpg);
    background-size: cover;
    background-position-y: center;
    /* border: #fff solid 1px;   */
    box-sizing: border-box;
    padding: 150px;
}

.container {
    width: 500px;
    height: 350px;
    background-color: rgba(255, 255, 255, 0.7);
    /* opacity:0.6;  */
    /* background: transparent; */
    margin: 0 auto;
    border-radius: 10px;
}

.title {
    height: 150px;
    line-height: 150px;
    text-align: center;
    font-size: 36px;
    font-weight: bold;
}

.inputs {
    font-size: 18px;
    line-height: 40px;
    margin-bottom: 10px;
}

.btn {
    width: 200px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background-color: #f00;
    color: #fff;
    border-radius: 15px;
    margin: 50px auto;
    cursor: pointer;
}
</style>
